
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0867
 * @Author : WangRuoyu 
 * @Date : 2023/5/23 15:43
 */

#include "iostream"

using namespace std;

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        for (int j = 2; j <= x / j; ++j) {
            if (x % j == 0) {
                int cnt = 0;
                while (x % j == 0) {
                    cnt++;
                    x /= j;
                }
                printf("%d %d\n", j, cnt);
            }
        }

        if (x > 1) printf("%d %d\n", x, 1);

        printf("\n");
    }

    return 0;
}